class Solution {
public:
    int get(int n) {
        int s = 0;
        while (n) {
            int t = n % 10;
            s += t * t;
            n /= 10;
        }
        return s;
    }
    bool isHappy(int n) {
        long long slow = n, fast = n;
        do {

            slow=get(slow);
            fast=get(get(fast));
            if(slow==1 || fast==1)
                return true;
        } while (slow != fast) ;
        return false;
    }
};
